<template>
	<view>
		<view class="search-box">
			<uni-search-bar @input="input" cancelButton="none" :radius="100" ></uni-search-bar>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				timer:null,
				kw:'',
				//搜索列表
				searchResults: []
				
			};
		},
		methods:{
			input(e){
				 clearTimeout(this.timer)
				  // 重新启动一个延时器，并把 timerId 赋值给 this.timer
				  this.timer = setTimeout(() => {
				    // 如果 500 毫秒内，没有触发新的输入事件，则为搜索关键词赋值
				    this.kw = e
					// 调用一个方法
				    this.getSearchList()
				  }, 500)
			
			},
			getSearchList(){
				if(this.kw === ''){
					this.searchResults = []
					return
				}
				uni.$http.gat('/api/public/v1/goods/qsearch', { query: this.kw })
				if(res.meta.status !== 200)return nui.$showMsg()
				this.searchResults = res.message
			}
		}
	}
</script>

<style lang="scss">
.search-box{
	position: relative;
	top: 0;
	z-index: 999;
}
</style>
